import pandas as pd
import requests
import json
from datetime import datetime, timedelta


# 读取 Excel 文件并指定 sheet 页
excel_file_path = r'C:\Users\luowenjie\Desktop\客服热线\数据\20240401_0531.xlsx'
sheet_name = 'sheet1'  # 替换为你的 sheet 页名称

# 使用 pandas 读取 Excel 文件
df = pd.read_excel(excel_file_path, sheet_name=sheet_name)

# 获取所有 uid 列表，忽略空值
uid_list = df['ID'].dropna().astype(str).tolist()

# 定义批量处理的大小
batch_size = 100

# 按批次处理 uid
for i in range(0, len(uid_list), batch_size):
    # 获取当前批次的 uid
    batch_uids = uid_list[i:i + batch_size]
    # 将当前批次的 uid 拼接成以逗号分隔的字符串
    uids_str = ",".join(batch_uids)
    # 构造 API URL
    api_url = f"http://43.138.150.59:8088/nbpAdmin/dataFill/startAnalyzeTask?ids={uids_str}"
    print(f"api_url: {api_url}")

    # 发起请求
    payload = {}
    headers = {}
    try:
        # 记录请求开始时间
        start_time = datetime.now()
        print(f"开始提交内容分析,:{start_time}")
        response = requests.request("GET", api_url, headers=headers, data=payload)
        # 检查响应状态
        if response.status_code == 200:
            print(f"批次 {i // batch_size + 1} 提交分析成功")
        else:
            print(f"批次 {i // batch_size + 1} 提交分析失败，状态码: {response.status_code}")
    except Exception as e:
        print(f"批次 {i // batch_size + 1} 请求发生错误: {e}")